<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width initial-scale=1 user-scalable=no"/>
  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="https://imgcache.qq.com/qcloud/cloudbase-js-sdk/1.6.0/cloudbase.full.js"></script>
  <script src="../cloudbase/cloudbase-login.js"></script>
  <script src="../cloudbase/cloudbase-api.js"></script>
  <link rel="stylesheet" href="../js/bootstrap-4.5.3-dist/css/bootstrap.css">
  <script src="../js/bootstrap-4.5.3-dist/js/bootstrap.bundle.js"></script>
  <title>登录</title>
  <style>
    html{
      width:100%;height: 100%;
    }
    body{
      width:100%;
      height: 100%;
      display: flex;
      align-items: center;
      align-content: center;
      justify-items: center;
      justify-content: center;
    }
    label{
      color:rgba(0,0,0,0.5);
    }
  </style>
</head>
<body class="p-2">

<section class="container-sm p-2 rounded">
  <h2 class="h3 text-center font-weight-bolder">注册</h2>
  <h5 class="h5 text-center text-secondary">诗歌本</h5>
  <div>
    <div class="form-group">
      <label for="email">邮箱 <span class="small text-info">将用作登录时用的账号</span></label>
      <input type="email" class="form-control" id="email" autocomplete="on">
    </div>
    <div class="form-group">
      <label for="pwd">密码 <span class="small text-info">密码长度不小于 8 位，不大于 32 位，需要包含字母和数字。</span></label>
      <input type="password" class="form-control" id="pwd" autocomplete="off">
    </div>
    <div class="form-group">
      <label for="pwdnext">确认密码</label>
      <input type="password" class="form-control" id="pwdnext" autocomplete="off">
    </div>
    <div class="form-check clearfix">
      <a href="./login.html" class="float-right mr-2">登录</a>
<!--      <a href="" class="float-right mr-2">忘记密码？</a>-->
    </div>
    <button type="button" class="btn btn-primary" onclick="zhuce()">注册</button>
  </div>
</section>

</body>
</html>
<script>
init()
async function init(){
  await anonymouslogin()

}
async function zhuce(){
  const email = $('#email').val()
  const pwd = $('#pwd').val()
  const pwdnext = $('#pwdnext').val()
  let res
  if(email==''){
    alert('请填写邮箱地址')
    return
  }
  if(pwd==''){
    alert('请填写密码')
    return
  }
  if(pwdnext==''){
    alert('请填写确认密码')
    return
  }
  if(pwd!==pwdnext){
    alert('两次密码填写不一致')
    return
  }

  zhuzeEmail(email,pwd).then(res=>{
    console.log(res);
    alert('注册成功，请在您的邮件内点击确认确认进行确认注册。')
    window.location.href = 'login.html'
  }).catch(err=>{
    let errmsg = JSON.parse(err.message)
    console.log(errmsg);
    confirm('错误代码：'+errmsg.msg + '\n注册失败，请检查邮箱或密码填写是否正确，或此账号已经注册了')
  })

}

</script>

